package br.unifor.cct.mia.initialize;

import java.awt.Point;
import java.util.List;

import br.unifor.cct.mia.dataenhancement.Attribute;
import br.unifor.cct.mia.dataenhancement.Structure;
import br.unifor.cct.mia.evolutionary.Particula;
import br.unifor.cct.mia.util.Configurations;
import br.unifor.cct.mia.util.Methods;

public class PSOMVRandonInitialize implements Initialize {

	@SuppressWarnings("unchecked")
	public Object execute(Object value) {
		Object[] o = (Object[])value;
		Configurations config = (Configurations)o[0];
		List<Particula> particulas = (List<Particula>)o[1];
		List mvPositions = (List) o[2];
		Structure structure = (Structure) o[3];
		
        for (int i = 0; i < config.getPopsize(); i++) {
        	
        	Particula p = new Particula(config);  	
        	p.setFitness(0);
        	p.setPBest(new Particula(config));
            for (int j = 0; j < p.getPosition().length; j++) {      
            	
              	Point point = (Point)mvPositions.get(j);
            	Attribute att = structure.getAttribute(point.y);
            	
            	double minVal = att.getMin();
            	double maxVal = att.getMax();
            	
            	p.setLower(minVal, j);
            	p.setUpper(maxVal, j);
            	p.getPosition()[j] = Methods.randIntValue((int)minVal, (int)maxVal);
            	p.getVelocity()[j] = Methods.randIntValue((int)minVal, (int)maxVal);
            }       
            particulas.add(p);
        }
	        
		return particulas;
	}

}
